<template>
	<view>
		<view class="container" v-if="WEBCONFIG?.custom_tabbar==1">
			<view class="item" v-for="(item,index) in TABBAR" :key='index' @click="jump(item)">
				<image class="icon" :src="item.path == page ? item.select_icon:item.icon"></image>
				<text class="text"
					:style="{color:item.path == page ? WEBCONFIG?.tabbar_select_color: WEBCONFIG?.tabbar_color }">{{item.name}}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { ref, watch, onBeforeMount, nextTick, getCurrentInstance } from "vue";
	import { useUserStore, useRefs, useWebConfigStore, useTabbarStore } from "@/stores/index";
	import { $page } from "@/utils";
	const { TABBAR } = useRefs(useTabbarStore());
	const { WEBCONFIG } = useRefs(useWebConfigStore());
	const page = ref()
	onBeforeMount(() => {
		tab()
	})
	const tab = () => {
		const pages = getCurrentPages();
		// 获取当前页面的实例
		const currentPage = pages[pages.length - 1];
		// 获取页面路径
		const pagePath = currentPage.route;
		page.value = '/' + pagePath
	}

	const jump = (e) => {
		if (e.type == 2) {
			$page.open(e.path)
		}
		if (e.type == 1) {
			$page.switch(e.path)
		}
	}
</script>

<style scoped lang="scss">
	.container {
		z-index: 9999;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom) !important;
		padding-bottom: env(safe-area-inset-bottom) !important;
		display: flex;
		align-items: center;
		border-top: 2rpx solid #eee;

		.item {
			width: 0;
			flex-grow: 1;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding: 5px 0px;

			.icon {
				width: 24px;
				height: 24px;
				padding-bottom: 4px;
			}

			.text {
				font-size: 12px;
			}
		}
	}
</style>